Handle assignments to global variables from the init function - #253
Conversation
|
@k4n4ry, thank you for submitting the PR! We'll take a look soon and follow up with you. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #253 +/- ##
==========================================
+ Coverage 87.54% 87.62% +0.07%
==========================================
Files 79 79
Lines 9465 9510 +45
==========================================
+ Hits 8286 8333 +47
+ Misses 937 936 -1
+ Partials 242 241 -1 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
|
|
||
| // getInitFuncDecl searches for the init function declaration in the given *ast.File. | ||
| // It returns the *ast.FuncDecl representing the init function if found, or nil otherwise. | ||
| func getInitFuncDecl(file *ast.File) *ast.FuncDecl { |
There was a problem hiding this comment.
This only returns the first init function. I believe there can be an arbitrary number of them.
There was a problem hiding this comment.
Thank you. I have made the changes you suggested and added additional tests.
|
@SongShawn |
|
@sonalmahajan15 |
|
I'm updating your branch since we recently merged CI fixes, which are required for the CI to pass on forked repositories. I'll review the code this week :) |
Golden TestWarning ❌ NilAway errors reported on stdlib are different 📉. 2223 errors on base branch (main, f3e3099) Diffs+ /opt/hostedtoolcache/go/1.25.12/x64/src/archive/tar/writer.go:543:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - tar/writer.go:304:27: unassigned variable `spb` passed as arg `p` to `Write()`
+ - tar/writer.go:540:26: passed as parameter `b` to `regFileWriter.Write()` (implementing `Writer.Write()`)
+ - tar/writer.go:543:7: function parameter `b` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/archive/tar/writer.go:583:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - tar/writer.go:304:27: unassigned variable `spb` passed as arg `p` to `Write()`
+ - tar/writer.go:580:29: passed as parameter `b` to `sparseFileWriter.Write()` (implementing `Writer.Write()`)
+ - tar/writer.go:583:7: function parameter `b` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/archive/zip/zip_test.go:431:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - flate/deflate.go:171:33: unassigned variable `window` passed as arg `input` to `writeBlock()`
+ - flate/huffman_bit_writer.go:478:16: function parameter `input` passed as arg `bytes` to `writeBytes()`
+ - flate/huffman_bit_writer.go:185:10: function parameter `bytes` passed as arg `b` to `write()`
+ - flate/huffman_bit_writer.go:136:28: function parameter `b` passed as arg `p` to `Write()`
+ - zip/zip_test.go:421:24: passed as parameter `p` to `suffixSaver.Write()` (implementing `Writer.Write()`)
+ - zip/zip_test.go:431:7: function parameter `p` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/bytes/bytes.go:404:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - decodemeta/decodefile.go:175:11: result 0 of `GetPackagePayload()` lacking guarding; passed as arg `p` to `Write()` via the assignment(s):
+ - `r.GetPackagePayload(...)` to `pp` at decodemeta/decodefile.go:172:2
+ - io/multi.go:83:23: passed as parameter `p` to `multiWriter.Write()` (implementing `Writer.Write()`)
+ - io/multi.go:85:20: function parameter `p` passed as arg `p` to `Write()`
+ - testing/testing.go:1127:24: passed as parameter `p` to `outputWriter.Write()` (implementing `Writer.Write()`)
+ - testing/testing.go:1141:28: function parameter `p` passed as arg `s` to `SplitAfter()`
+ - bytes/bytes.go:446:18: function parameter `s` passed as arg `s` to `genSplit()`
+ - bytes/bytes.go:404:7: function parameter `s` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/bytes/bytes.go:404:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - decodemeta/decodefile.go:175:11: result 0 of `GetPackagePayload()` lacking guarding; passed as arg `p` to `Write()` via the assignment(s):
+ - `r.GetPackagePayload(...)` to `pp` at decodemeta/decodefile.go:172:2
+ - testing/testing.go:1127:24: passed as parameter `p` to `outputWriter.Write()` (implementing `Writer.Write()`)
+ - testing/testing.go:1141:28: function parameter `p` passed as arg `s` to `SplitAfter()`
+ - bytes/bytes.go:446:18: function parameter `s` passed as arg `s` to `genSplit()`
+ - bytes/bytes.go:404:7: function parameter `s` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/bytes/bytes.go:404:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - flate/deflate.go:171:33: unassigned variable `window` passed as arg `input` to `writeBlock()`
+ - flate/huffman_bit_writer.go:478:16: function parameter `input` passed as arg `bytes` to `writeBytes()`
+ - flate/huffman_bit_writer.go:185:10: function parameter `bytes` passed as arg `b` to `write()`
+ - flate/huffman_bit_writer.go:136:28: function parameter `b` passed as arg `p` to `Write()`
+ - io/multi.go:83:23: passed as parameter `p` to `multiWriter.Write()` (implementing `Writer.Write()`)
+ - io/multi.go:85:20: function parameter `p` passed as arg `p` to `Write()`
+ - testing/testing.go:1127:24: passed as parameter `p` to `outputWriter.Write()` (implementing `Writer.Write()`)
+ - testing/testing.go:1141:28: function parameter `p` passed as arg `s` to `SplitAfter()`
+ - bytes/bytes.go:446:18: function parameter `s` passed as arg `s` to `genSplit()`
+ - bytes/bytes.go:404:7: function parameter `s` sliced into
+ /opt/hostedtoolcache/go/1.25.12/x64/src/bytes/bytes.go:404:7: Potential nil panic detected. Observed nil flow from source to dereference point:
+ - flate/deflate.go:171:33: unassigned variable `window` passed as arg `input` to `writeBlock()`
+ - flate/huffman_bit_writer.go:478:16: function parameter `input` passed as arg `bytes` to `writeBytes()`
+ - flate/huffman_bit_writer.go:185:10: function parameter `bytes` passed as arg `b` to `write()`
+ - flate/huffman_bit_writer.go:136:28: function parameter `b` passed as arg `p` to `Write()`
+ - io/multi.go:83:23: passed as parameter `p` to `multiWriter.Write()` (implementing `Writer.Write()`)
+ - io/multi.go:85:20: function parameter `p` passed
...(truncated)...
f` accessed field `name`
- /opt/hostedtoolcache/go/1.25.12/x64/src/os/os_test.go:1090:6: Potential nil panic detected. Observed nil flow from source to dereference point:
- - os/file_unix.go:52:9: literal `nil` returned as error result 0 of `rename()`
- - os/file.go:438:9: result 0 of `rename()` found in at least one path of `Rename()` for return in position 0
- - os/os_test.go:1090:6: result 0 of `Rename()` accessed field `Op` via the assignment(s):
- - `Rename(...)` to `err` at os/os_test.go:1087:2
-
- (Same nil source could also cause potential nil panic(s) at 11 other place(s): "os/os_test.go:1091:75", "os/os_test.go:1093:6", "os/os_test.go:1094:72", "os/os_test.go:1096:6", "os/os_test.go:1097:70", "os/os_test.go:1127:6", "os/os_test.go:1128:75", "os/os_test.go:1130:6", "os/os_test.go:1131:72", "os/os_test.go:1133:6", and "os/os_test.go:1134:70".)
- /opt/hostedtoolcache/go/1.25.12/x64/src/os/removeall_test.go:507:6: Potential nil panic detected. Observed nil flow from source to dereference point:
- - os/removeall_at.go:19:10: literal `nil` returned as error result 0 of `removeAll()`
- - os/path.go:74:9: result 0 of `removeAll()` found in at least one path of `RemoveAll()` for return in position 0
- - os/removeall_test.go:507:6: result 0 of `RemoveAll()` called `Error()` via the assignment(s):
- - `RemoveAll(...)` to `err` at os/removeall_test.go:502:2
- /opt/hostedtoolcache/go/1.25.12/x64/src/os/root.go:91:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - os/os_test.go:1906:13: unassigned variable `r` used as receiver to call `OpenFile()`
- - os/root.go:121:2: read by method receiver `r` used as receiver to call `logOpen()`
- - os/root.go:280:21: read by method receiver `r` used as receiver to call `Name()`
- - os/root.go:91:9: read by method receiver `r` accessed field `root`
- /opt/hostedtoolcache/go/1.25.12/x64/src/os/root_openat.go:371:6: Potential nil panic detected. Observed nil flow from source to dereference point:
- - os/root.go:352:9: literal `nil` returned from `splitPathInRoot()` in position 0 via the assignment(s):
- - `nil` to `suffix` at os/root.go:316:3,
- - `append(...)` to `parts` at os/root.go:351:2
- - os/root_openat.go:371:6: result 0 of `splitPathInRoot()` sliced into via the assignment(s):
- - `splitPathInRoot(...)` to `newparts` at os/root_openat.go:456:4,
- - `newparts` to `parts` at os/root_openat.go:474:4
-
- (Same nil source could also cause potential nil panic(s) at 6 other place(s): "os/root_openat.go:439:33", "os/root_openat.go:456:64", "os/root_openat.go:456:75", "os/root_openat.go:465:42", "os/root_openat.go:478:13", and "os/root_openat.go:479:25".)
- /opt/hostedtoolcache/go/1.25.12/x64/src/reflect/type.go:2077:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - reflect/all_test.go:7230:22: nilable value assigned into global variable `Tptr`
- - reflect/all_test.go:7315:31: global variable `Tptr` passed as arg `t` to `SliceOf()`
- - reflect/type.go:2077:9: function parameter `t` called `common()`
- /opt/hostedtoolcache/go/1.25.12/x64/src/reflect/type.go:2077:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - reflect/all_test.go:7230:28: nilable value assigned into global variable `Tscalarptr`
- - reflect/all_test.go:7338:39: global variable `Tscalarptr` passed as arg `elem` to `ArrayOf()`
- - reflect/type.go:2649:26: function parameter `elem` passed as arg `t` to `SliceOf()`
- - reflect/type.go:2077:9: function parameter `t` called `common()`
- /opt/hostedtoolcache/go/1.25.12/x64/src/reflect/type.go:2077:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - reflect/all_test.go:7230:40: nilable value assigned into global variable `Tptrscalar`
- - reflect/all_test.go:7327:46: global variable `Tptrscalar` passed as arg `elem` to `ArrayOf()`
- - reflect/type.go:2649:26: function parameter `elem` passed as arg `t` to `SliceOf()`
- - reflect/type.go:2077:9: function parameter `t` called `common()`
- /opt/hostedtoolcache/go/1.25.12/x64/src/reflect/type.go:2077:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - reflect/all_test.go:7230:52: nilable value assigned into global variable `Tbigptrscalar`
- - reflect/all_test.go:7329:31: global variable `Tbigptrscalar` passed as arg `t` to `SliceOf()`
- - reflect/type.go:2077:9: function parameter `t` called `common()`
- /opt/hostedtoolcache/go/1.25.12/x64/src/reflect/type.go:2077:9: Potential nil panic detected. Observed nil flow from source to dereference point:
- - reflect/all_test.go:7230:5: nilable value assigned into global variable `Tscalar`
- - reflect/all_test.go:7344:41: global variable `Tscalar` passed as arg `elem` to `ArrayOf()`
- - reflect/type.go:2649:26: function parameter `elem` passed as arg `t` to `SliceOf()`
- - reflect/type.go:2077:9: function parameter `t` called `common()` |
|
Hi, any news on landing this? I've been running this locally and it's very useful 😄 |

fixes #56
run()to retrieve the init function from the file.getGlobalConsumers(), analyzed assignments to global variables from the init function and used it as one of the criteria for determining consumer creation.Please provide comments if this implementation differs from nilaway's coding practices or design principles. Thank you.